import time
import xlrd
import xlwt






class logcat():

    x1 = xlwt.Workbook(encoding="utf-8")
    sheet = x1.add_sheet("1",cell_overwrite_ok=True)
    row0 = ['Warning', 'Info', 'Error', 'Debug']
    for i in range(len(row0)):
        sheet.write(0, i, row0[i])
    x1.save(r"D:\LogCat.xls")
    D = 0
    W = 0
    E = 0
    I = 0
    o = 0
    a = open(r'D:/a.log', 'r', encoding='utf-8').read()
    b = a.split('\n\n')
    # a = []
    # f = open(r"D:\a.log",encoding="utf-8")
    # while True:
    #     lines = f.readline()
    #     a.append(lines)
    #     if not lines:
    #         break
    # with open(file) as f:
    #     while True:
    #         lines = f.readline()
    #         if not lines:
    #             break
    # a.append(lines.split('\n\n'))

    print(a)



    for i in b:
        if i[0] == "D":
            D += 1
        elif i[0] == "W":
            W+=1
        elif i[0] =="E":
            E+=1
        elif i[0] == "I":
            I+=1
        else:
            o+=1
    SUM = []
    SUM.append([D,W,E,I])
    print(SUM)
    wied = [W, I, D, E]
    for p in range(len(wied)):
        sheet.write(1, p, wied[p])
        x1.save(r"D:\LogCat.xls")
        time.sleep(2)










































